package com.learn;

import java.util.Arrays;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 第二种使用servlt，filter,listener的方式
 * @author Romanceling
 *
 */
@Configuration
public class MyConfig {

	@Bean
	public ServletRegistrationBean<BookServlet> createBookServlet(){
		ServletRegistrationBean<BookServlet> servlet = new ServletRegistrationBean<BookServlet>(new BookServlet(),"/book.do");
		return servlet;
	}
	
	@Bean
	public FilterRegistrationBean<EncoFilter> createEncoFilter(){
		FilterRegistrationBean<EncoFilter> filter = new FilterRegistrationBean<EncoFilter>();
		filter.setFilter(new EncoFilter());
		filter.setUrlPatterns(Arrays.asList("/book.do"));
		return filter;
	}
	
	@Bean
	public ServletListenerRegistrationBean<SartupListener> createSartupListener(){
		ServletListenerRegistrationBean<SartupListener> listener = new ServletListenerRegistrationBean<SartupListener>(new SartupListener());
		return listener;
	}
}
